package com.hackcloud.shardingjdbc.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
@AutoConfigureAfter({DruidDataSource.class})
public class DynamicDataSourceConfig {


//    @Bean
//    public AbstractRoutingDataSource routingDataSource(DruidDataSource druidDataSource, @Qualifier("dataSource") DataSource dataSource) {
//        DynamicDataSource dynamicDataSource = new DynamicDataSource();
//        Map<Object, Object> targetDataSource = new HashMap<>();
//        targetDataSource.put(DynamicDataSourceHolder.DataBaseType.SHARDING_DATA_SOURCE, dataSource);
//        targetDataSource.put(DynamicDataSourceHolder.DataBaseType.DEFAULT_DATA_SOURCE, druidDataSource);
//        dynamicDataSource.setTargetDataSources(targetDataSource);
//        dynamicDataSource.setDefaultTargetDataSource(druidDataSource);
//        return dynamicDataSource;
//    }


}
